﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DataAccessLibrary;

namespace BusinessLayer
{
    public class ClsManageAttendance
    {
        public int EmployeeID { get; set; }
        public int AttendanceID { get; set; }
        public DateTime? DateAttended { get; set; }
        public DateTime? StartTime { get; set; }
        public DateTime? EndTime { get; set; }
        public void GetEmployeeAttendance(int employeeID)
        {
            using (OleDataClient data = new OleDataClient())
            {
                DataTable dt = data.GetDataTable("Select * from Attendance where Format([DateAttended],'yyyy-mm-dd')='" + Utility.GetDateYYYYMMDD(DateTime.Now) + "' and EmployeeID=" + employeeID.ToString(), "Attendance");
                if (dt.Rows.Count > 0)
                {
                    AttendanceID = Convert.ToInt32(dt.Rows[0]["AttendanceID"]);
                    DateAttended = Utility.GetValidDateElseNull(dt.Rows[0]["DateAttended"]);
                    StartTime = Utility.GetValidDateElseNull(dt.Rows[0]["StartTime"]);
                    EndTime = Utility.GetValidDateElseNull(dt.Rows[0]["EndTime"]);
                }
            }
        }
        public DataTable GetEmployeeAttendance(int employeeID, DateTime fromDate , DateTime toDate)
        {
            using (OleDataClient data = new OleDataClient())
            {
                DataTable dt = data.GetDataTable("Select * from Attendance where Format([DateAttended],'yyyy-mm-dd') between '" + Utility.GetDateYYYYMMDD(fromDate) + "' and '" + Utility.GetDateYYYYMMDD(toDate) + "' and EmployeeID=" + employeeID.ToString(), "Attendance");
                return dt;
            }
        }
        public void UpdateEmployeeAttendance(int employeeID)
        {
            using (OleDataClient data = new OleDataClient())
            {
                               
              data.ExecuteNonQuery("Update Attendance set StartTime = '" + StartTime + "', EndTime =  '" + EndTime + "'" +  " where AttendanceID= " + AttendanceID.ToString() + " and EmployeeID=" + EmployeeID.ToString());
                 
            }

        }

    }
}
